package com.cqan.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.cqan.entity.pk.LongEntity;

@Entity
//表名与类名不相同时重新定义表名.
@Table(name = "TBL_FIELD")
//默认的缓存策略.
@SuppressWarnings("serial")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AtomField extends LongEntity {

	private FieldType fieldType;
	
	private String name;
	
	private String value;
	
	private Report report;
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "RID")
	public Report getReport() {
		return report;
	}

	public void setReport(Report report) {
		this.report = report;
	}

	public AtomField(){}
	
	public AtomField(String name,String value, FieldType fieldType){
		this.fieldType =fieldType;
		this.name = name;
		this.value = value;
	}
	
	@Column(name="FIELD_TYPE")
	@Enumerated(EnumType.STRING)
	public FieldType getFieldType() {
		return fieldType;
	}

	@Column(name="NAME")
	public String getName() {
		return name;
	}

	@Column(name="VALUE")
	public String getValue() {
		return value;
	}

	public void setFieldType(FieldType fieldType) {
		this.fieldType = fieldType;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
